package org.delphy.indy2.containers
{
	import caurina.transitions.Tweener;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.filters.GlowFilter;
	import flash.utils.Timer;
	
	import mx.containers.Canvas;
	import mx.core.Application;
	import mx.managers.PopUpManager;

	public class CarbonNotificationWindow extends Canvas
	{
		
		public var transitionTime:Number=1.3;	//unit: s
		public var delayTime:Number=3000;	//unit: ms
		private var timer:Timer;
		
		public var position:String="center";	
		public var space:Number=20;
		
		public static const POSITION_CENTER:String="center";
		public static const POSITION_TOP_LEFT:String="topLeft";
		public static const POSITION_TOP_RIGHT:String="topRight";
		public static const POSITION_BOTTOM_LEFT:String="bottomLeft";
		public static const POSITION_BOTTOM_RIGHT:String="bottomRight";
		
		private var shadowSize:Number;
		private var shadowDistance:Number;
		private var shadowColor:Number=0x448CCB;
		
		public function CarbonNotificationWindow()
		{
			super();
			
			styleName="carbonNotificationWindow";
			
			horizontalScrollPolicy="off";
			verticalScrollPolicy="off";
			
			visible=false;
			
		}
		
		public function popUp():void{		

			if(Tweener.isTweening(this)){
				return;
			}
			
			alpha=0;			
			
			// Initialize position
			
			switch(position){
				case POSITION_CENTER:
					x=Application.application.width/2-width/2;
					y=Application.application.height/2-height/2;
					break;
				case POSITION_TOP_LEFT:
					x=space;
					y=space;
					break;
				case POSITION_TOP_RIGHT:
					x=Application.application.width-width-space;
					y=space;
					break;
				case POSITION_BOTTOM_LEFT:
					x=space;
					y=Application.application.height-height-space;
					break;
				case POSITION_CENTER:
					x=Application.application.width-width-space;
					y=Application.application.height-height-space;
					break;
				

			}
			

			PopUpManager.addPopUp(this,DisplayObject(Application.application),false);
			
			if(!visible){
				visible=true;
			}
			
			Tweener.addTween(this,{alpha:1,time:transitionTime,onComplete:onPopUpAnimationComplete});
		}

		private function onPopUpAnimationComplete():void{
			timer=new Timer(delayTime);			
			timer.addEventListener(TimerEvent.TIMER,close);
			timer.start();
		}
		
		public function close(evt:Event=null):void{
			timer.stop();
			Tweener.addTween(this,{alpha:0,time:transitionTime,onComplete:onCloseAnimationComplete});
		}
		
		private function onCloseAnimationComplete():void{
			PopUpManager.removePopUp(this);
		}
		
	}
}